# -*- coding: utf-8 -*-
# @Time    : 2024/8/28 10:55
# @Author  : floraachy
# @File    : repo_issue_label_page
# @Software: PyCharm
# @Desc: 项目标记页面

# 标准库导入
# 第三方库导入
import allure
# 本地应用/模块导入
from utils.base_utils.base_page import BasePage


class RepoIssueLabelPage(BasePage):
    """项目-X疑修详情页-项目标记"""
    # 【创建标记】按钮
    locator_create_label_btn = "//a[text()='创建标记']"
    # “名称”输入框
    locator_name_input = "//input[@placeholder='名称15字以内']"
    # “描述”输入框
    locator_desc_input = "//input[@placeholder='描述30字以内']"
    # “颜色”层
    locator_color_div = "//div[@class='color']"
    # “颜色” 六进制值输入框
    locator_color_input = "//input[@id='rc-editable-input-1']"
    # “颜色” 选择框
    locator_color_choose_div = "//div[@class='cover']"
    # 【确定】按钮
    locator_confirm_btn = "//span[text()='确 定']/.."
    # 列表第一条数据的颜色
    locator_first_label_color = "(//ul[@class='signlist']/li[1]//span)[1]"
    # 列表第一条数据的名称
    locator_first_label_name = "(//ul[@class='signlist']/li[1]//span)[2]"
    # 列表第一条数据的描述
    locator_first_label_desc = "(//ul[@class='signlist']/li[1]//p)[2]"
    # 【编辑】按钮
    locator_first_label_edit_btn = "(//a[text()='编辑'])[1]"
    # 【删除】按钮
    locator_first_label_delete_btn = "(//a[text()='删除'])[1]"
    # 【确认删除】按钮
    locator_confirm_delete_btn = "//span[text()='确认删除']/.."

    @allure.step("访问项目标记详情页面：/{repo_owner}/{repo_identifier}/issues/sign")
    def navigate(self, repo_owner, repo_identifier):
        """
        访问项目标记页面
        """
        self.visit(f"/{repo_owner}/{repo_identifier}/issues/sign")

    @allure.step("点击【创建标签】按钮")
    def click_create_label_button(self):
        """点击创建标签按钮"""
        self.click(self.locator_create_label_btn)

    @allure.step("点击【确定】按钮")
    def click_confirm_button(self):
        """点击【确定】按钮"""
        self.click(self.locator_confirm_btn)

    @allure.step("点击列表第一条数据的【删除】按钮")
    def click_first_label_delete_button(self):
        """点击列表第一条数据的【删除】按钮"""
        self.click(self.locator_first_label_delete_btn)

    @allure.step("点击【确认删除】按钮")
    def click_confirm_delete_button(self):
        """点击【确认删除】按钮"""
        self.click(self.locator_confirm_delete_btn)

    @allure.step("点击列表第一条数据的【编辑】按钮")
    def click_first_label_edit_button(self):
        """点击列表第一条数据的【编辑】按钮"""
        self.click(self.locator_first_label_edit_btn)

    @allure.step("输入标签名称: {name}")
    def input_label_name(self, name):
        """输入标签名称"""
        self.input(self.locator_name_input, name)

    @allure.step("输入标签描述: {desc}")
    def input_label_desc(self, desc):
        """输入标签描述"""
        self.input(self.locator_desc_input, desc)

    @allure.step("选择标签颜色: {color}")
    def choose_label_color(self, color):
        """选择标签颜色"""
        self.click(self.locator_color_div)
        self.input(self.locator_color_input, color)
        self.click(self.locator_color_choose_div)
